import './App.css';
import Frame from './component/Frame/Index';
import {Route,Redirect,Switch } from 'react-router-dom';
import {adminRoutes} from './router/index';
import Index from './pages/index'
function App() {
  return localStorage.getItem('token') ? (
    <Frame>
      <Switch>
        <Route path="/admin/index" component={Index} exact />
        {
          adminRoutes.map(routes=>{
            if(!routes.children){
              return (
                <Route key={routes.path} path={routes.path} exact={routes.exact} render={
                  rp=>{
                    return <routes.component {...rp} />;
                  }
                } />
              )
            }else{
              return (
                routes.children.map(route=>{
                  return (
                    <Route key={route.path} path={route.path} exact={route.exact} render={
                      rp=>{
                        return <route.component {...rp} />;
                      }
                    } />
                  )
                })
              )
            }
          })
        }
        <Redirect to='/404' />
      </Switch>
    </Frame>
  ) : <Redirect to='/login' />
}

export default App;
